<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <title><spring:message code="bigcargo_create_style" /></title>
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
    <script src="${ctxStatic}/js/jquery-1.9.1.min.js"></script>
    <script src="${ctxStatic}/dateCalendar/WdatePicker.js"></script>
    <script src="${ctxStatic}/js/common.js"></script>
	<script type="text/javascript">
        // 面辅料List
        var objMaterials;
		$(document).ready(function() {
			// 下拉选框带搜索功能
			$("#materialTypeCd,#brandId,#materialStyle,#materialWeave,#ognizationID").select2();
			materialOgnizationFun();
			searchListForm();
		});
		// 检索
		function searchListForm() {
			var params = $("#searchForm").serialize();
			$("#activity_pane").showLoading();
			$.post("${ctx}/common/material/searchList", params,
					function(result) {
						var listHtml = result["commonMaterialHtml"];
                        var pageHtml = result["page"];
                        objMaterials = result["materialList"];
						$("#listHtml").html(listHtml);
						$("#paging").html(pageHtml);
						$("#activity_pane").hideLoading();
					}, 'json');
		}
		// 添加
        function add() {
			var ognizationID = $("#ognizationID").find("option:selected").val();
			var brandID = $("#brandId").find("option:selected").val();
			popup('900px','640px','${ctx}/material/stock/form?winFlag=0&materialOgnizationId='+ognizationID+'&brandID='+brandID);
            
        }
      //获取 iframe 数量 
		var frLength = window.parent.frames.length;
		//父画面下标 
		var parentIndex = frLength-2;
        function selectedCall() {
            var indexList="";
            var indexLen = $("#listHtml").find(".selected").length;
            for (var i = 0; i < indexLen; i++){
                if (i==indexLen-1) {
                    indexList += $("#listHtml").find(".selected")[i].id;
                } else {
                    indexList += $("#listHtml").find(".selected")[i].id + ",";
                }
            }
            window.parent.frames[parentIndex].selectMaterialCallBack(indexList,objMaterials);
            closeWin();
        }
        // 重置
        function clean(){
            $("input").val("");
            $("#searchForm").submit();
        }
        //选择按钮事件
        function selectFunction(obj){
        	// 判断是否被选中
        	var bolSelected = $(obj).hasClass("selected");
        	if (bolSelected) {
        		$(obj).removeClass("selected");
        	} else {
        		$(obj).addClass("selected");
        	}
        }
        
      //客户品牌联动
        function materialOgnizationFun() {
        	var brandID = "${commonMaterialItem.brandId}";
        	var materialOgnizationId=$("#ognizationID").find("option:selected").val();    	
        	var pleaseSelect = '<option value="">' + '<spring:message code="style_pleaseSelect" />'+'</option>';
        	param={"materialOgnizationId":materialOgnizationId,"brandID":brandID};
        	$.post("${ctx}/material/stock/findBrand",param,function(result){            
        		 var html = "";
                 var brandList = result["brandNameCnList"];
                 $(brandList).each(function(i,e) {
                     html += "<option value='"+e.apBrandId+"'";
                     if (brandID==e.apBrandId) {
                    	 html += "selected='selected'";
    				 }
                     html += ">"+ e.brandCn+ "</option>";
     			});
                 $("#brandId").html(pleaseSelect+html);
                 $("#brandId").select2();
            },'json');
    	}
    </script>
</head>
<body>
<form id="searchForm" method="post">
<div class="tabBoxSm" id="activity_pane">
    <input type="hidden" id = "imageFlg" value="${commonMaterialItem.imageFlg}">
    <div class="tabSm smOrderBox" style="width:1230px">
        <div class="items clearfix">
            <div class="col-50 clearfix">
                <strong style="font-size:15px;"><spring:message code="changeMaterial"/></strong>
            </div>
            <div class="col-50 clearfix" >
                <div style="float:right;">
                    <!-- 选择 -->
                    <button type="button" class="btn-cj" onclick="add()"><spring:message code="commMaterial_add"/></button>
                    <!-- 选择 -->
                    <button type="button" class="btn-cj" onclick="selectedCall()"><spring:message code="style_selectOK"/></button>
                    <!-- 重置 -->
                    <button type="button" class="btn-js" onclick="clean()"><spring:message code="common_reset"/></button>
                    <!-- 检索 -->
                    <button type="button" class="btn-js" onclick="searchListForm()"><spring:message code="commom_check"/></button>
                    <!-- 关闭 -->
                    <button type="button" class="btn-js" onclick="closeWin()"><spring:message code="btn_cancle"/></button>
                </div>
            </div>
            <br><hr></hr>
        </div>
        <div class="items clearfix">
            <div class="col-16 clearfix">
                <!-- 面辅料类别 -->
			 <p class="tit_muster"><spring:message code="commonMaterial_Category"/></p>
			  <select style="width:170px" id="materialTypeCd" name="materialTypeCd">
			   <option value=""><spring:message
									code="order_please_choose" /></option>
			<c:forEach items="${materialListCategory}" var="item">
				<option <c:if test="${fn:split(commonMaterialItem.materialTypeCd, '-')[1] eq item.itemValue}">selected="selected"</c:if>
                        value="${item.itemCode}-${item.itemValue}">${item.itemName}</option>
			</c:forEach>
			</select>
            </div>
            <div class="col-16 clearfix">
                <!-- 客户名称 -->
                <p class="tit_muster"><spring:message code="commonMaterial_ognizitionName"/></p>
                <select style="width:170px" id="ognizationID" name="ognizationID" onchange="materialOgnizationFun();">
                    <option value=""><spring:message
                            code="order_please_choose" /></option>
                    <c:forEach items="${ogizationList}" var="item">
                        <option
                                <c:if test="${commonMaterialItem.venderId eq item.ognizationID }">selected="selected"</c:if>
                                <c:if test="${commonMaterialItem.ognizationName eq item.ognizationName }">selected="selected"</c:if>
                                value="${item.ognizationID}">${item.ognizationName}</option>
                    </c:forEach>
                </select>
            </div>
            <div class="col-16 clearfix">
                <!-- 客户品牌 -->
                <p class="tit_muster"><spring:message code="commonMaterial_brandName"/></p>
                <select style="width:170px" id="brandId" name="brandId">
                    <option value=""><spring:message
                            code="order_please_choose" /></option>
                    <c:forEach items="${brandList}" var="item">
                        <option
                                <c:if test="${commonMaterialItem.brandId eq item.apBrandId }">selected="selected"</c:if>
                                value="${item.apBrandId}">${item.heabrandCn}</option>
                    </c:forEach>
                </select>
            </div>
        </div>
            <div class="items clearfix">
                <div class="col-16 clearfix">
                    <!-- 风格 -->
                    <p class="tit_muster"><spring:message code="commonMaterial_style"/></p>
                    <select style="width:170px" id="materialStyle" name="materialStyle">
                        <option value=""><spring:message
                                code="order_please_choose" /></option>
                        <c:forEach items="${materialStyleList}" var="item">
                            <option value="${item.itemCode}-${item.itemValue}">${item.itemName}</option>
                        </c:forEach>
                    </select>
                </div>
                <div class="col-16 clearfix">
                    <!-- 织法 -->
                    <p class="tit_muster"><spring:message code="commonMaterial_weave"/></p>
                    <select style="width:170px" id="materialWeave" name="materialWeave">
                        <option value=""><spring:message
                                code="order_please_choose" /></option>
                        <c:forEach items="${materialWeaveList}" var="item">
                            <option value="${item.itemCode}-${item.itemValue}">${item.itemName}</option>
                        </c:forEach>
                    </select>
                </div>
                <div class="col-16 clearfix">
                    <!-- 物料号 -->
                    <p class="tit_muster"><spring:message code="commonMaterial_material"/></p>
                    <input type="text" style="width:170px" id="materialCode" name="materialCode" value="" />
                </div>
            </div>
        </div>
		<%-- <div class="items clearfix" style="margin: 0px;">
            <div class="col-16 clearfix" style="width:100%;margin-left:11px">
                <strong style="font-size:12px;"><spring:message code="commonMaterial_layout"/></strong>
            </div>
        </div> --%>
    <div class="tableArea overflowX">
        <div class="tableScroll" style="height: 471px;overflow: auto;width: 1213px;">
            <table cellpadding="0" class="tableHead" style="width:1100px">
                <thead>
                <tr>
                    <!-- No. -->
                    <th><p class="commonTable-No">
                        <spring:message code="common_no" />
                    </p></th>
                    <!-- 物料图片 -->
                    <th><p class="commonTable-File">
                        <spring:message code="commonMaterial_pic" />
                    </p></th>
                    <!-- 物料名称/编码 -->
                    <th><p class="commonTable-CodeName">
                        <spring:message code="commonMaterial_no_name" />
                    </p></th>
                    <!-- 物料类别 -->
                    <th><p class="commonTable-cagoty">
                        <spring:message code="commonMaterial_styleCategory" />
                    </p></th>
                    <!-- 来源类别 -->
                    <th><p class="commonTable-come">
                        <spring:message code="commonMaterial_come" />
                    </p></th>
                    <!-- 客户名称 -->
                    <th><p class="commonTable-ogname">
                        <spring:message code="commonMaterial_ognizitionName" />
                    </p></th>
                    <!-- 客户品牌 -->
                    <th><p class="commonTable-brand">
                        <spring:message code="commonMaterial_brandName" />
                    </p></th>
                    <!-- 幅宽 -->
                    <th><p class="commonTable-spec">
                        <spring:message code="commonMaterial_spec" />
                    </p></th>
                    <!-- 克重 -->
                    <th><p class="commonTable-weight">
                        <spring:message code="commonMaterial_weight" />
                    </p></th>
                    <!-- 成分 -->
                    <th><p class="commonTable-position">
                        <spring:message code="commonMaterial_composition" />
                    </p></th>
                    <!-- 纱支密度 -->
                    <th><p class="commonTable-threadcount">
                        <spring:message code="commonMaterial_threadcount" />
                    </p></th>
                    <!-- 风格 -->
                    <th><p class="commonTable-style">
                        <spring:message code="commonMaterial_style" />
                    </p></th>
                    <!-- 颜色 -->
                    <th><p class="commonTable-color">
                        <spring:message code="commonMaterial_color" />
                    </p></th>
                    <!-- 织法 -->
                    <th><p class="commonTable-weave">
                        <spring:message code="commonMaterial_weave" />
                    </p></th>
                    <!-- 库存数量 -->
                    <th><p class="commonTable-weave">
                        <spring:message code="commonMaterial_quantity" />
                    </p></th>
                </tr>
                </thead>
            </table>
            <table cellpadding="0" class="tableBody">
                <tbody id="listHtml">
                </tbody>
            </table>
        </div>
</div>
        <div id="paging"></div>
    </div>
<input type="hidden" id ="frameFlg" value="">
</form>
</body>
</html>
